var Portal = {
    layerIndex: -1,
};
$(function () {
    $.parser.parse(); // 解析整个页面
    //上报总体情况
    Portal.initMrlistCnt();
    //近一年单病种上报情况
    Portal.drawMainChart();
    //费用,住院日
    Portal.drawSysSumChart();
    //病种上报情况,科室上报情况,医生上报情况
    Portal.drawQCSumChart();
    Portal.drawLocSumChart();
    Portal.drawDocSumChart();
    //病种自动填报率分析,病种填报用时分析
    Portal.drawARatioChart();
    Portal.drawUseTimeChart();
});

$('.index-value').on('click',function(){
    var idName = $(this).attr('id');
    var index = Sys.open_c('关注病例列表', '/analysis/portal/list?idName=' + idName , null, function (){
    });
    this.layerIndex = index;
});

$('.more-oper').on('click',function(){
    if ($(this).attr('id')=='UseTime-More'){//病种填报用时情况
        Portal.showUseTimeAlias();
    }else if ($(this).attr('id')=='ARatio-More'){//病种自动填报率情况
        Portal.showARatioAlias();
    }else if ($(this).attr('id')=="QCSumMore"){
        var idName = $(this).attr('id');
        var qcTimeDimens = $("input[name='QCRido']:checked").val();
        var index = Sys.open_c('关注病例列表', '/analysis/portal/list?idName=' + idName + '&qcTimeDimens=' + qcTimeDimens, null, function (){
        });
        this.layerIndex = index;
    }else if ($(this).attr('id')=="LocSumMore"){
        var idName = $(this).attr('id');
        var qcTimeDimens = $("input[name='LocRido']:checked").val();
        var index = Sys.open_c('关注病例列表', '/analysis/portal/list?idName=' + idName + '&qcTimeDimens=' + qcTimeDimens, null, function (){
        });
        this.layerIndex = index;
    }else if ($(this).attr('id')=="DocSumMore"){
        var idName = $(this).attr('id');
        var qcTimeDimens = $("input[name='DocRido']:checked").val();
        var index = Sys.open_c('关注病例列表', '/analysis/portal/list?idName=' + idName + '&qcTimeDimens=' + qcTimeDimens, null, function (){
        });
        this.layerIndex = index;
    }
});

Portal.showUseTimeAlias=function(){
    var index = Sys.open_c('病种填报用时分析', '/analysis/portal/useTime', null, function (){
    });
    this.layerIndex = index;
}

Portal.showARatioAlias=function(list){
    var index = Sys.open_c('病种自动填报率分析', '/analysis/portal/autoRatio', null, function (){
    });
    this.layerIndex = index;
}

Portal.initMrlistCnt = function(){
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectMrlistCnt", function (data) {
        var upCount = data.upCount;
        var incaseCount = data.incaseCount;
        $('#todayRep').html(upCount[0]);
        $('#monthRep').html(upCount[1]);
        $('#yearRep').html(upCount[2]);
        $('#totalRep').html(upCount[3]);
        $('#readyRep').html(incaseCount[0]);
        $('#readyCheck').html(incaseCount[1]);
        $('#readyUp').html(incaseCount[2]);
        $('#back').html(incaseCount[3]);
        $('#donotRep7').html(data.donotRep7);
        $('#donotRep10').html(data.donotRep10);
        $('#donotRep30').html(data.donotRep30);
        $('#donotRep90').html(data.donotRep90);

        /*$('#todayRep').attr('data-list',data[0].split('^')[1]);
        $('#monthRep').attr('data-list',data[1].split('^')[1]);
        $('#yearRep').attr('data-list',data[3].split('^')[1]);
        $('#totalRep').attr('data-list',data[4].split('^')[1]);
        $('#readyRep').attr('data-list',data[5].split('^')[1]);
        $('#readyCheck').attr('data-list',data[6].split('^')[1]);
        $('#readyUp').attr('data-list',data[7].split('^')[1]);
        $('#back').attr('data-list',data[8].split('^')[1]);
        $('#donotRep7').attr('data-list',data[9].split('^')[1]);
        $('#donotRep10').attr('data-list',data[10].split('^')[1]);
        $('#donotRep30').attr('data-list',data[11].split('^')[1]);
        $('#donotRep90').attr('data-list',data[12].split('^')[1]);*/
    }, function (data){
    });
    ajax.set(params);
    ajax.start();
}

Portal.drawMainChart = function(){
    var xdata=[];
    var ydata=[];
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectMainChart", function (data) {
        var dataArr = data.mainChart
        var datalen = dataArr.length
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            xdata.push(row.date);
            ydata.push(row.count);
        }
        var myChart = echarts.init(document.getElementById('main'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '近一年上报情况'
            },
            tooltip: {},
            legend: {},
            xAxis: {
                data: xdata,
                axisLine: {
                    lineStyle: {

                    }
                }
            },
            yAxis: {},
            series: [
                {
                    name: '例数',
                    type: 'line',
                    smooth: true,
                    showAllSymbol: true,
                    symbol: 'emptyCircle',
                    symbolSize: 15,
                    data: ydata,
                    markLine: {
                        data: [{ type: 'average', name: '月均上报' }]
                    }
                },

            ]
        };
        myChart.setOption(option);
    }, function (data){
    });
    ajax.set(params);
    ajax.start();
}

Portal.drawSysSumChart = function(){
    //疾病系统费用展现
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectSysSumChart", function (data) {
        var xdata = []
        var ydata = []
        var dataArr = data.averageData
        var datalen = dataArr.length
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            xdata.push(row.description);
            ydata.push(row.averageCosts);
        }
        var myChart = echarts.init(document.getElementById('CostInfo'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '疾病费用'
            },
            tooltip: {
                formatter: '{b}<br/>平均住院费用：' + '{c}'
            },
            legend: {},
            xAxis: {
                data: xdata
            },
            yAxis: {},
            series: [
                {
                    name: '平均费用',
                    type: 'bar',
                    data: ydata,
                    barMaxWidth:'40px',
                    itemStyle: {
                        borderRadius: 5,
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            { offset: 0, color: '#83bff6' },
                            { offset: 0.5, color: '#188df0' },
                            { offset: 1, color: '#188df0' }
                        ])
                    },
                }
            ]
        };
        myChart.setOption(option);

        //疾病系统住院日展现
        var xdata = []
        var ydata = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            xdata.push(row.description);
            ydata.push(row.averageDays);
        }
        var myChart = echarts.init(document.getElementById('IndaysInfo'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '住院天数'
            },
            tooltip: {
                formatter: '{b}<br/>平均住院日：' + '{c}'
            },
            legend: {},
            xAxis: {
                type: 'category',
                data: xdata
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '平均住院天数',
                    type: 'bar',
                    data: ydata,
                    barMaxWidth:'40px',
                    itemStyle: {
                        borderRadius: 5,
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            { offset: 0, color: '#83bff6' },
                            { offset: 0.5, color: '#188df0' },
                            { offset: 1, color: '#188df0' }
                        ])
                    },
                }
            ]
        };
        myChart.setOption(option);
    }, function (data){
    });
    ajax.set(params);
    ajax.start();



}

Portal.drawQCSumChart = function(){
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectQCSumChart", function (data) {
        var dataArr = data.upEntitys
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.code
            dataobj.push(tobj)
        }
        dataobj.sort(function(a, b){return b.value - a.value});
        dataobj=dataobj.slice(0,10);
        var myChart = echarts.init(document.getElementById('QCSum'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '病种上报情况',
            },
            tooltip: {
                trigger: 'item'
            },
            legend: {
                orient: 'vertical',
                left: 'right'
            },
            series: [
                {
                    name: '上报例数',
                    type: 'pie',
                    radius:[70,100],
                    roseType: 'area',
                    itemStyle: {
                        borderRadius: 5
                    },
                    label: {
                        show: false
                    },
                    data: dataobj
                }
            ]
        };
        myChart.setOption(option);
    }, function (data){
    });
    params.qcTimeDimens = $("input[name='QCRido']:checked").val();
    ajax.set(params);
    ajax.start();
}

Portal.drawLocSumChart = function(){
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectLocSumChart", function (data) {
        var dataArr = data.upLoc
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.description
            dataobj.push(tobj)
        }
        dataobj.sort(function(a, b){return b.value - a.value});
        dataobj=dataobj.slice(0,10);

        var xdata = []
        var ydata = []
        dataobj.forEach(function(item,index){
            xdata.push(item.name);
            ydata.push(item.value);
        });

        var myChart = echarts.init(document.getElementById('LocSum'));
        var option = {
            title: {
                text: '科室上报情况'
            },
            tooltip: {},
            angleAxis: {
            },
            radiusAxis: {
                type: "category",
                data: xdata,
                z: 10
            },
            polar: {radius: [10, '80%']},
            series: [{
                name: "例数",
                type: "bar",
                data: ydata,
                coordinateSystem: "polar",
                label: {
                    show: true,
                    position: 'middle',
                    formatter: '{c}'
                }
            }],
            legend: {},


        };
        myChart.setOption(option);
    }, function (data){
    });
    params.qcTimeDimens = $("input[name='LocRido']:checked").val();
    ajax.set(params);
    ajax.start();
}

Portal.drawDocSumChart = function(){
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectDocSumChart", function (data) {
        var dataArr = data.upDoc
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.count
            tobj.name = row.description
            dataobj.push(tobj)
        }
        dataobj.sort(function(a, b){return b.value - a.value});
        dataobj=dataobj.slice(0,10);

        var myChart = echarts.init(document.getElementById('DocSum'));
        var option = {
            title: {
                text: '医生上报情况'
            },
            tooltip: {
            },
            legend: {
                orient: 'vertical',
                left: 'right'
            },
            series: [
                {
                    type: 'pie',
                    data: dataobj,
                    label: {
                        show: false
                    },
                }
            ]
        };
        myChart.setOption(option);
    }, function (data){
    });
    params.qcTimeDimens = $("input[name='DocRido']:checked").val();
    ajax.set(params);
    ajax.start();
}

Portal.drawARatioChart = function(sortflg){
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectARatioChart", function (data) {
        var dataArr = data.aRatioData
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.aRatio
            tobj.name = row.description
            dataobj.push(tobj)
        }
        //var sortflg = $("input[name='AutoRatio']:checked").val();
        if (sortflg=="ASC") {
            dataobj.sort(function(a, b){return a.value - b.value});
        }else{
            dataobj.sort(function(a, b){return b.value - a.value});
        }
        dataobj=dataobj.slice(0,10);
        var xdata = []
        var ydata = []
        dataobj.forEach(function(item,index){
            xdata.push(item.name);
            ydata.push(item.value);
        });
        var myChart = echarts.init(document.getElementById('ARatio'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '病种自动填报率分析'
            },
            tooltip: {
            },
            legend: {},
            xAxis: {
                data: xdata
            },
            yAxis: {
                type:'value',
                min:0,
                max:100
            },
            series: [
                {
                    name: '自动提取率(百分比)',
                    type: 'bar',
                    data: ydata,
                    showBackground: true,
                    barMaxWidth:'40px',
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            { offset: 0, color: '#83bff6' },
                            { offset: 0.5, color: '#188df0' },
                            { offset: 1, color: '#188df0' }
                        ])
                    },
                }
            ]
        };
        myChart.setOption(option);
    }, function (data){
    });
    ajax.set(params);
    ajax.start();
}

Portal.drawUseTimeChart = function(sortflg){
    var params = {};
    var ajax = new $ax(Sys.backendPath + "/analysis/portal/selectUseTimeChart", function (data) {
        var dataArr = data.useTimeData
        var datalen = dataArr.length
        var dataobj = []
        for (var i = 0; i < datalen; i++) {
            var row = dataArr[i]
            var tobj = new Object()
            tobj.value = row.avgUseTime
            tobj.name = row.description
            dataobj.push(tobj)
        }
        if (sortflg=="ASC") {
            dataobj.sort(function(a, b){return a.value - b.value});
        }else{
            dataobj.sort(function(a, b){return b.value - a.value});
        }
        dataobj=dataobj.slice(0,10);
        var xdata = [],ydata = []
        dataobj.forEach(function(item,index){
            xdata.push(item.name);
            ydata.push(item.value);
        });
        var myChart = echarts.init(document.getElementById('UseTime'));
        // 指定图表的配置项和数据
        var option = {
            title: {
                text: '病种填报平均用时分析'
            },
            tooltip: {

            },
            legend: {},
            xAxis: {
                type: 'category',
                data: xdata
            },
            yAxis: {

            },
            series: [
                {
                    name: '填报平均用时(分钟)',
                    type: 'bar',
                    data: ydata,
                    barMaxWidth:'40px',
                    itemStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            { offset: 0, color: '#83bff6' },
                            { offset: 0.5, color: '#188df0' },
                            { offset: 1, color: '#188df0' }
                        ])
                    },
                }
            ]
        };
        myChart.setOption(option);
    }, function (data){
    });
    ajax.set(params);
    ajax.start();
}